home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCSmallEiffel / lib_se / formal_generic_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  3.4 KB  |  159 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class FORMAL_GENERIC_LIST
  17. --   
  18. -- To store the list of formal generic arguments of (a generic) class.
  19. --
  20.    
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.    
  25. feature 
  26.    
  27.    start_position: POSITION;
  28.      -- Of first "[".
  29.    
  30. feature {NONE}
  31.  
  32.    list: ARRAY[FORMAL_GENERIC_ARG];
  33.  
  34. feature 
  35.    
  36.    make(sp: like start_position; l: like list) is
  37.       require
  38.      sp /= Void;
  39.      l /= Void;
  40.      not l.empty;
  41.      l.lower = 1;
  42.       local
  43.      rank, i: INTEGER;
  44.      fga: FORMAL_GENERIC_ARG;
  45.       do
  46.      start_position := sp;
  47.      list := l;
  48.      from  
  49.         i := l.upper;
  50.      until
  51.         i = 0
  52.      loop
  53.         fga := l.item(i);
  54.         check
  55.            fga /= Void;
  56.         end;
  57.         rank := index_of(fga.name);
  58.         if rank /= i then
  59.            eh.add_position(l.item(rank).start_position);
  60.            eh.add_position(fga.start_position);
  61.            fatal_error("Class name appears twice in formal %
  62.                %generic list (VCFG-2).");
  63.         end;
  64.         i := i - 1;
  65.      end;
  66.       ensure
  67.      start_position = sp;
  68.      list = l;
  69.       end;
  70.    
  71.    count: INTEGER is
  72.       do
  73.      Result := list.upper;
  74.       end;
  75.    
  76.    item(i: INTEGER): FORMAL_GENERIC_ARG is
  77.       require
  78.      1 <= i;
  79.      i <= count;
  80.       do
  81.      Result := list.item(i);
  82.       ensure
  83.      Result /= Void;
  84.       end;
  85.    
  86.    pretty_print is
  87.       local
  88.      i: INTEGER;
  89.       do
  90.      fmt.put_character('[');
  91.      fmt.level_incr;
  92.      from  
  93.         i := 1;
  94.      until
  95.         i > list.upper
  96.      loop
  97.         list.item(i).pretty_print;
  98.         i := i + 1;
  99.         if i <= list.upper then
  100.            fmt.put_string(",");
  101.         end;
  102.      end;
  103.      fmt.put_character(']');
  104.      fmt.level_decr;
  105.       ensure
  106.      fmt.indent_level = old fmt.indent_level;
  107.       end;
  108.  
  109.    short is
  110.       local
  111.      i: INTEGER;
  112.       do
  113.      short_print.hook_or("open_sb","[");
  114.      from  
  115.         i := 1;
  116.      until
  117.         i > list.upper
  118.      loop
  119.         list.item(i).short;
  120.         i := i + 1;
  121.         if i <= list.upper then
  122.            short_print.hook_or("fgl_sep",",");
  123.         end;
  124.      end;
  125.      short_print.hook_or("close_sb","]");
  126.       end;
  127.  
  128. feature {FORMAL_GENERIC_ARG}
  129.  
  130.    index_of(n: CLASS_NAME): INTEGER is
  131.      -- Index of `n' or 0 when not found.
  132.       require
  133.      n /= Void
  134.       local
  135.      to_string: STRING;
  136.       do
  137.      from
  138.         to_string := n.to_string;
  139.         Result := list.upper;
  140.      until
  141.         Result = 0 or else
  142.         to_string = list.item(Result).name.to_string
  143.      loop
  144.         Result := Result - 1;
  145.      end;
  146.       ensure
  147.      0 <= Result;
  148.      Result <= list.upper;
  149.       end;
  150.    
  151. invariant
  152.    
  153.    list.lower = 1;
  154.    
  155.    not list.empty;
  156.    
  157. end -- FORMAL_GENERIC_LIST
  158.  
  159.